home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Movie Toolbox / MyMultipleMoviesApp ƒ / MyApplication.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  9.5 KB  |  416 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyApplication.c
  3.     
  4.     Contains:    My Application Shell.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        03/14/94    JW        Re-Created for Universal Headers.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    <Types.h>
  23. #include    <Memory.h>
  24. #include    <QuickDraw.h>
  25. #include    <Palettes.h>
  26. #include    <QDOffscreen.h>
  27. #include    <Errors.h>
  28. #include    <Fonts.h>
  29. #include    <Dialogs.h>
  30. #include    <Windows.h>
  31. #include    <Menus.h>
  32. #include    <Events.h>
  33. #include    <Desk.h>
  34. #include    <DiskInit.h>
  35. #include    <OSUtils.h>
  36. #include    <Resources.h>
  37. #include    <ToolUtils.h>
  38. #include    <AppleEvents.h>
  39. #include    <EPPC.h>
  40. #include    <GestaltEqu.h>
  41. #include    <Processes.h>
  42. #include    <Balloons.h>
  43. #include    <Aliases.h>
  44. #include    <MixedMode.h>
  45. #include    <Scrap.h>
  46. #include    <LowMem.h>
  47.  
  48. #include    <Movies.h>
  49.  
  50. #include    "MyApplication Shell (2.0).h"
  51. #include    "MyApplication.h"
  52. #include    "BetterFlattenMovie.h"
  53. #include    "MyMovieStuff.h"
  54.  
  55. /* ------------------------------------------------------------------------- */
  56.  
  57. //    These globals are used by the shell and must be defined:
  58.  
  59. long        gQDfeature, gWindowCount;
  60. Str255        gMyAboutTitle = "\pQuickTime App";
  61. Str255        gMyAboutDesc = "\pThis is a multiple movie playback app.";
  62.  
  63. /* ------------------------------------------------------------------------- */
  64.  
  65. //    MyInitialize is called at init time after the toolbox is initialized.  This routine is
  66. //    called only once.
  67.  
  68. OSErr MyInitialize()
  69. {
  70.     OSErr        err;
  71.  
  72.     //    We require QuickTime so make sure it is available.
  73.     err = Gestalt(gestaltQuickTime, &gQDfeature);
  74.     if ( err != noErr )
  75.         return ( err );
  76.  
  77.     err = EnterMovies();
  78.     if ( err != noErr )
  79.         return ( err );
  80.         
  81.     return ( noErr );
  82. }
  83.  
  84. //    Depending on the value of the constant MYEVENTDEF, this routine may have different
  85. //    calling frequency.
  86. //    If MYEVENTDEF == 2, then this routine gets called for every
  87. //       window owned by the application of type MAS_WINDOWDOC per iteration of the event loop
  88. //       if the event is NOT a null event.  MyEvent can assume that the grafport and gdevice
  89. //       are set to the window being passed.
  90. //    If MYEVENTDEF == 1, then this routine gets called once per event loop is the
  91. //       event is NOT a null event.  theWindow will be nil.
  92. //    If MYEVENTDEF == 0, this routine never gets called.
  93. //    Returning true indicates that the event was handled and can be ignored by the normal
  94. //    event handler.
  95.  
  96. Boolean MyEvent(WindowPtr theWindow, EventRecord *myEvent)
  97. {
  98.     WindowInfoHandle    myWinfo;
  99.     Boolean                ret;
  100.     
  101.     ret = false;
  102.     myWinfo = (WindowInfoHandle) GetWRefCon(theWindow);
  103.     if ( (**myWinfo).theMC != nil ) {
  104.         ret = MCIsPlayerEvent((**myWinfo).theMC, myEvent);
  105.     }
  106.     
  107.     return ( ret );
  108. }
  109.  
  110. //    Depending on the value of the constant MYIDLEDEF, this routine may have different
  111. //    calling frequency.
  112. //    If MYIDLEDEF == 2, then this routine gets called for every
  113. //       window owned by the application of type MAS_WINDOWDOC per iteration of
  114. //       the event loop.  You can assume that the port and gdevice are set to the window.
  115. //    If MYIDLEDEF == 1, then this routine gets called once per event loop.  theWindow will be nil.
  116. //    If MYIDLEDEF == 0, this routine never gets called.
  117.  
  118. void MyIdle(WindowPtr theWindow)
  119. {
  120.     WindowInfoHandle    myWinfo;
  121.     
  122.     myWinfo = (WindowInfoHandle) GetWRefCon(theWindow);
  123.     if ( (**myWinfo).theMC != nil ) {
  124.         MCIdle((**myWinfo).theMC);
  125.     }
  126. }
  127.  
  128. //    MyDraw is called when redrawing the window is needed.  The port and gdevice
  129. //    is already set and begin and end update are called for MyDraw.
  130.  
  131. void MyDraw(WindowPtr theWindow)
  132. {
  133.     //    Erase a black background for movie.
  134.     PaintRect(&(theWindow->portRect));
  135. }
  136.  
  137. //    This routine gets called once when the application is quitting.
  138. //    This gives the app the chance to clean up.
  139.  
  140. void MyFinishup()
  141. {
  142.     //    As discussed in issue #13 of 'develop' magazine, it is better to let QuickTime
  143.     //    call ExitMovies().
  144. }
  145.  
  146. //    This routine is called whenever the app receives a suspend or resume event.  This
  147. //    allows the yield time (passed to WaitNextEvent) to be changed.  I.e., if you don't
  148. //    do much processing the in background, you should set the yield to a high value
  149. //    when the suspend message is received.
  150.  
  151. long MyYieldTime(long message)
  152. {
  153.     if ( message )
  154.         //    Resume message
  155.         return ( 0 );
  156.     else
  157.         //    Suspend message
  158.         return ( 30 );
  159. }
  160.  
  161. //    If the shell's doCommand routine can not process the menu selection, then this routine is
  162. //    called.  Do not call HiliteMenu because it is called by the shell.
  163. //    If the command can not be handled, this it must be an error and the shell will
  164. //    present a FATAL error to the user.
  165.  
  166. OSErr MyDoCommand(short theMenu, short theItem)
  167. {
  168.     WindowPtr                frontWindow;
  169.     WindowInfoHandle        myWinfo;
  170.     
  171.     switch ( theMenu ) {
  172.         case kMENU_COLLECTION:
  173.             if ( IsMyWindow(frontWindow = FrontWindow()) ) {
  174.                 myWinfo = (WindowInfoHandle) GetWRefCon(frontWindow);
  175.                 switch ( theItem ) {
  176.                     case kMENU_MACADDRESATOM:
  177.                         Mac_AddMovieResAtom(&((**myWinfo).refNum), &((**myWinfo).theFSSpec));
  178.                         break;
  179.                     case kMENU_MACADDALL:
  180.                         Mac_AddMovieAll(&((**myWinfo).refNum), &((**myWinfo).theFSSpec));
  181.                         break;
  182.                     case kMENU_CROSSADDALL:
  183.                         Cross_AddMovieAll(&((**myWinfo).refNum), &((**myWinfo).theFSSpec));
  184.                         break;
  185.                     case kMENU_BOTHADDALL:
  186.                         Both_AddMovieAll(&((**myWinfo).refNum), &((**myWinfo).theFSSpec));
  187.                         break;
  188.                     default:
  189.                         return ( theItem );
  190.                 }
  191.                 adjustMoviesMenu(frontWindow);
  192.             } else
  193.                 SysBeep(50);
  194.             break;
  195.             
  196.         case kMENU_MOVIES:
  197.             if ( IsMyWindow(frontWindow = FrontWindow()) )
  198.                 SelectThisMovie(theItem);
  199.             else
  200.                 SysBeep(50);
  201.             break;
  202.             
  203.         default:
  204.             return ( theItem );
  205.     }
  206.     
  207.     return ( noErr );
  208. }
  209.  
  210. void MyDoKeyDown(EventRecord *myEvent)
  211. {
  212. }
  213.  
  214. void MyInContent(WindowPtr foundWindow, Point where)
  215. {
  216. }
  217.  
  218. void MyZoomWindow(WindowPtr foundWindow, short windowPart)
  219. {
  220.     if ( windowPart == 8 ) {
  221.     } else {
  222.     }
  223.  
  224.     ZoomWindow(foundWindow, windowPart, true);
  225. }
  226.  
  227. void MyAdjustMenus()
  228. {
  229. }
  230.  
  231. /* ------------------------------------------------------------------------- */
  232.  
  233. WindowPtr createMoviesWindow(FSSpec *movieFSSpec, short theRefNum);
  234. WindowPtr createMoviesWindow(FSSpec *movieFSSpec, short theRefNum)
  235. {
  236.     WindowPtr                myWindow;
  237.     WindowInfoHandle        myWinfo;
  238.     Rect                    windowRect;
  239.     GDHandle                myMaxDevice;
  240.  
  241.     //    Create window.
  242.     myMaxDevice = GetMaxDevice(&((**LMGetGrayRgn()).rgnBBox));
  243.     windowRect = (**((**myMaxDevice).gdPMap)).bounds;
  244.     myWindow = NewCWindow(0L, &windowRect, (*movieFSSpec).name, 1, noGrowDocProc, (WindowPtr) -1, true, 0L);
  245.     OffsetRect(&windowRect, -windowRect.left, -windowRect.top);
  246.     SetMyWindow(myWindow);
  247.     SetGWorld((CGrafPtr) myWindow, GetMainDevice());
  248.     
  249.     //    This handle must be locked because we dereference it all the time.
  250.     myWinfo = (WindowInfoHandle) NewHandle(sizeof(WindowInfo));
  251.     MoveHHi((Handle) myWinfo);
  252.     HLock((Handle) myWinfo);
  253.     SetWRefCon(myWindow, (long) myWinfo);
  254.     
  255.     (**myWinfo).theFSSpec = *movieFSSpec;
  256.     (**myWinfo).refNum = theRefNum;
  257.     (**myWinfo).theMovie = nil;
  258.     (**myWinfo).theMC = nil;
  259.     (**myWinfo).moviename[0] = 0;
  260.     (**myWinfo).resId = -1;
  261.     (**myWinfo).movieOffset = -1;
  262.     
  263.     return ( myWindow );
  264. }
  265.  
  266. void MyNew()
  267. {
  268.     WindowPtr                myWindow;
  269.     StandardFileReply        reply;
  270.     short                    myRefNum;
  271.     MenuHandle                myMenu;
  272.     
  273.     if ( gWindowCount > 0 ) {
  274.         SysBeep(50);
  275.         return;
  276.     }
  277.     
  278.     //    Ask for a new document file.  If none given, then quit.
  279.     StandardPutFile("\pNew document", "\pMovie Collection", &reply);
  280.     if ( !reply.sfGood )
  281.         return;
  282.  
  283.     //    Use QuickTime to create movie file.
  284.     if ( CreateMovieFile(&reply.sfFile, 'WnG1', smSystemScript,
  285.             createMovieFileDeleteCurFile | createMovieFileDontCreateMovie, &myRefNum, nil) ) {
  286.         Alert(kALERT_CANTNEW, nil);
  287.         return;
  288.     }
  289.     
  290.     myWindow = createMoviesWindow(&(reply.sfFile), myRefNum);
  291.     gWindowCount += 1;
  292.     
  293.     //    Add new menu.
  294.     adjustMoviesMenu(myWindow);
  295. }
  296.  
  297. //    If theFSS is not nil, then the file to be opened is specified in the FSSpec.
  298. //    MyOpen must make window frontmost so that it can be printed from finder.
  299. void MyOpen(FSSpec *theFSS)
  300. {
  301.     OSErr                    err;
  302.     WindowPtr                myWindow;
  303.     StandardFileReply        reply;
  304.     FSSpec                    myFSSpec;
  305.     SFTypeList                types;
  306.     short                    myRefNum;
  307.     MenuHandle                myMenu;
  308.  
  309.     if ( gWindowCount > 0 ) {
  310.         SysBeep(50);
  311.         return;
  312.     }
  313.     
  314.     //    If theFSS was nil, then open a file manually.
  315.     if ( theFSS == nil ) {
  316.         types[0] = 'MooV';
  317.         StandardGetFilePreview(nil, 1, types, &reply);
  318.         if (!reply.sfGood)
  319.             return;
  320.         myFSSpec = reply.sfFile;
  321.     } else {
  322.         myFSSpec = *theFSS;
  323.     }
  324.  
  325.     //    Open movie file.
  326.     err = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
  327.     if ( myRefNum == -1 || err ) {
  328.         Alert(kALERT_ERROROPEN, nil);
  329.         return;
  330.     }
  331.     
  332.     myWindow = createMoviesWindow(&myFSSpec, myRefNum);
  333.     gWindowCount += 1;
  334.  
  335.     //    Add new menu.
  336.     adjustMoviesMenu(myWindow);
  337. }
  338.  
  339. void MyClose()
  340. {
  341.     WindowPtr            closeWindow;
  342.     WindowInfoHandle    myWinfo;
  343.     MenuHandle            myMenu;
  344.     
  345.     if ((closeWindow = FrontWindow()) == nil)
  346.         return;
  347.         
  348.     myWinfo = (WindowInfoHandle) GetWRefCon(closeWindow);
  349.  
  350.     if ((**myWinfo).theMC != nil)
  351.         DisposeMovieController((**myWinfo).theMC);
  352.     if ((**myWinfo).theMovie != nil);
  353.         DisposeMovie((**myWinfo).theMovie);
  354.     if ((**myWinfo).refNum != -1)
  355.         CloseMovieFile((**myWinfo).refNum);
  356.     DisposHandle((Handle) myWinfo);
  357.     DisposeWindow(closeWindow);
  358.     gWindowCount -= 1;
  359.     
  360.     //    Delete old menu.
  361.     adjustMoviesMenu(nil);
  362.     CompactMem(0xfffffff);
  363. }
  364.  
  365. void MySave()
  366. {
  367.     SysBeep(50);
  368. }
  369.  
  370. void MySaveAs()
  371. {
  372.     SysBeep(50);
  373. }
  374.  
  375. void MyPageSetup()
  376. {
  377.     SysBeep(50);
  378. }
  379.  
  380. void MyPrint()
  381. {
  382.     SysBeep(50);
  383. }
  384.  
  385. /* ------------------------------------------------------------------------- */
  386.  
  387. void MyUndo(void)
  388. {
  389.     SysBeep(50);
  390. }
  391.  
  392. void MyCut(void)
  393. {
  394.     SysBeep(50);
  395. }
  396.  
  397. void MyCopy(void)
  398. {
  399.     SysBeep(50);
  400. }
  401.  
  402. void MyPaste(void)
  403. {
  404.     SysBeep(50);
  405. }
  406.  
  407. void MyClear(void)
  408. {
  409.     SysBeep(50);
  410. }
  411.  
  412. void MySelectAll(void)
  413. {
  414.     SysBeep(50);
  415. }
  416.